package com.knife.excel;


import org.apache.poi.ss.usermodel.*;

import java.io.File;

/**
 * create by yongli on 2021-10-29 10:50
 * 文件读取模板，拿来就用
 * poi的基本类和使用方法
 * 在excel表中
 * <p>
 * 表单-
 * sheet页-
 * 行 row
 * 列 column
 * hssf是啥？
 */

public class ExcelRead {
    public static void main(String[] args) {
        String path = "/Users/yongli/Desktop/data.xlsx";
        try {
            Workbook workbook = WorkbookFactory.create(new File(path));
            Sheet sheet = workbook.getSheetAt(0);
            int width = sheet.getDefaultColumnWidth();
            short len = sheet.getDefaultRowHeight();
            System.out.println("width：" + width);
            System.out.println("len:" + len);

            for (int i = 0; i < len; i++) {
                Row row = sheet.getRow(i);
                for (int j = 0; j < width; j++) {
                    Cell cell = row.getCell(j);
                    if (cell != null) {
                        // 直接把类型都带出来
                        String val = cell.getStringCellValue();
                        System.out.println(val);
                    } else {
                        System.out.println("null value");
                    }
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
